package com.evil.account.util;

import com.evil.account.pojo.entity.Enterprise;
import com.evil.common.family.enums.RCodeEnum;
import com.evil.common.core.enums.SwitchEnum;
import com.evil.common.core.exception.BusinessException;

public class EnterpriseUtil {

    /**
     * 验证使企业是否有效
     *
     * @param enterprise enterprise
     */
    public static void validEnterprise(Enterprise enterprise) {
        if (enterprise == null) {
            throw new BusinessException(RCodeEnum.ENTERPRISE_NOT_EXIST);
        }

        if (enterprise.getIsDeleted() == null || SwitchEnum.isOpen(enterprise.getIsDeleted())) {
            throw new BusinessException(RCodeEnum.ENTERPRISE_NOT_EXIST);
        }

        if (enterprise.getIsEnable() == null || SwitchEnum.isClose(enterprise.getIsEnable())) {
            throw new BusinessException(RCodeEnum.USER_ENTERPRISE_DISABLED);
        }
    }

    /**
     * 验证使企业是否有效
     *
     * @param enterprise enterprise
     * @return boolean
     */
    public static boolean checkEnterprise(Enterprise enterprise) {
        if (enterprise == null) {
            return false;
        }

        if (enterprise.getIsDeleted() == null || SwitchEnum.isOpen(enterprise.getIsDeleted())) {
            return false;
        }
        return enterprise.getIsEnable() != null && !SwitchEnum.isClose(enterprise.getIsEnable());
    }

}
